package com.sdhs.businessfile.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sdhs.businessfile.domain.BusinessFile;
import com.sdhs.businessfile.domain.dto.BusinessFileDTO;
import com.sdhs.businessfile.service.IBusinessFileService;
import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.poi.ExcelUtil;

/**
 * 业务附件Controller
 *
 * @author mz
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/businessFile")
public class BusinessFileController extends BaseController {
    @Autowired
    private IBusinessFileService businessFileService;

    /**
     * 查询业务附件列表
     */
    @PreAuthorize("@ss.hasPermi('businessFile:businessFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessFileDTO businessFile) {
        startPage();
        List<BusinessFile> list = businessFileService.selectBusinessFileList(businessFile);
        return getDataTable(list);
    }

    /**
     * 导出业务附件列表
     */
    @PreAuthorize("@ss.hasPermi('businessFile:businessFile:export')")
    @Log(title = "业务附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessFileDTO businessFile) {
        List<BusinessFile> list = businessFileService.selectBusinessFileList(businessFile);
        ExcelUtil<BusinessFile> util =  new ExcelUtil<BusinessFile>(BusinessFile.class);
        util.exportExcel(response, list, "业务附件数据");
    }

    /**
     * 获取业务附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('businessFile:businessFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(businessFileService.selectBusinessFileById(id));
    }

    /**
     * 新增业务附件
     */
    @PreAuthorize("@ss.hasPermi('businessFile:businessFile:add')")
    @Log(title = "业务附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessFileDTO businessFile) {
        return toAjax(businessFileService.insertBusinessFile(businessFile));
    }

    /**
     * 修改业务附件
     */
    @PreAuthorize("@ss.hasPermi('businessFile:businessFile:edit')")
    @Log(title = "业务附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessFileDTO businessFile) {
        return toAjax(businessFileService.updateBusinessFile(businessFile));
    }

    /**
     * 删除业务附件
     */
    @PreAuthorize("@ss.hasPermi('businessFile:businessFile:remove')")
    @Log(title = "业务附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(businessFileService.deleteBusinessFileByIds(ids));
    }

    /**
     * 删除业务附件
     */
    @PreAuthorize("@ss.hasPermi('businessFile:businessFile:remove')")
    @Log(title = "业务附件", businessType = BusinessType.DELETE)
    @DeleteMapping("file/{id}")
    public AjaxResult del(@PathVariable Long id) {
        return toAjax(businessFileService.deleteBusinessFileById(id));
    }
}
